import time
st = time.time()
from itertools import permutations

index = [[0,6,7],[1,7,8],[2,8,9],[3,9,5],[4,5,6]]
dict_index = {}
index_len = len(index)
for inds in range(index_len):
    tmp = []
    for k in range(inds,inds+index_len):
        if k >= index_len:
            k_pro = k - 5
        else:
            k_pro = k
        tmp.extend(index[k_pro])
    dict_index[index[inds][0]] = tmp
print(dict_index)

max_res = 0
for i in permutations(range(1,11),10):
    #遍历所有排序
    if 10 not in i[:5]:
        #如果10不在前5个中，直接conticue
        continue
    if i[0]+i[6]+i[7]==i[1]+i[7]+i[8]==i[2]+i[8]+i[9]==i[3]+i[9]+i[5]==i[4]+i[5]+i[6]:
        startNum = min(i[:5])
        startInd = i[:5].index(startNum)
        numIndex = dict_index[startInd]
        num_str = ""
        for dk in numIndex:
            num_str = num_str + str(i[dk])
        num = int(num_str)
        if num > max_res:
            max_res = num

print(num)
print(time.time()-st)